package com.ncu.greendao;

import android.content.Context;
import android.view.View;

import com.ncu.greendao.db.DaoMaster;
import com.ncu.greendao.db.DaoSession;

import org.greenrobot.greendao.query.QueryBuilder;

//用于创建数据库、创建数据库表、包含增删改查的操作以及数据库的升级。
public class DaoManager {
    private DaoMaster.DevOpenHelper helper;
    private DaoSession daoSession;
    private DaoMaster daoMaster;
    private static DaoManager greenDaoManager;
    private String DBNAME = "GreenPal";

    public DaoManager(){

    }


    public void init(Context context){
        helper = new DaoMaster.DevOpenHelper(context,DBNAME);
        daoMaster = new DaoMaster(helper.getWritableDb());
        daoSession = daoMaster.newSession();
    }

    public static DaoManager getInstance(){
        if (greenDaoManager == null){
            greenDaoManager = new DaoManager();
        }
        return greenDaoManager;
    }

    public DaoMaster.DevOpenHelper getDevOpenHelper(){
        return helper;
    }

    public DaoMaster getDaoMaster() {
        return daoMaster;
    }

    public  DaoSession getDaoSession() {
        return daoSession;
    }

    public void closeDB(){
        if (helper != null){
            helper.close();
        }
    }
}